/**
 * 新用户注册用Action
 */
package teatime.core.web.action;

import java.util.Date;

import teatime.core.model.entity.Account;
import teatime.core.model.entity.Person;
import teatime.core.model.entity.StatusDetail;
import teatime.core.model.entity.TypeDetail;
import teatime.core.service.manager.AccountManager;
import teatime.core.service.manager.StatusDetailManager;
import teatime.core.web.action.base.BaseAction;
import teatime.core.bussiness.NormalRegister;
import teatime.core.bussiness.base.BaseRegister;

/**
 * @author ShenJie
 * 
 */
@SuppressWarnings("serial")
public class RegisterAction extends BaseAction {

	private AccountManager<Account> accountManager;
//	private StatusDetailManager<StatusDetail> statusManager;
	

	private String accountName;
	private String accountPassword;
	private String accountEmail;

	private Account account;
//	private StatusDetail statusDetail;
//	private TypeDetail typeDetail;

	public String execute() throws Exception {
		try {
//			 account = new Account();
//			 account.setAccountName(accountName);
//			 account.setAccountPassword(accountPassword);
			account = accountManager.findUniqueBy(account.PROP_ACCOUNT_NAME,
					accountName);
			if (account == null) {
				account = new Account();
				account.setAccountName(accountName);
				account.setAccountPassword(accountPassword);
				account.setAccountCreateDate(new Date());
				account.setAccountEmail(accountEmail);
//				statusDetail = statusManager.findUniqueBy(statusDetail.PROP_ID, "001");
				
				account.setAccountStatusId("001");
				account.setAccountStatusId("01");
//				account.setAccountStatus(statusDetail);
				account.setAccountTypeDetailId("001");
				account.setAccountTypeId("01");
				accountManager.save(account);
			}
//			 BaseRegister register = new NormalRegister(account);
//			 setResponse(register.doRegister());
		} catch (Exception ex) {
			setResponse(ERROR);
		}
		return null;
	}

	public void setAccountName(String accountName) {
		this.accountName = accountName;
	}

	public String getAccountName() {
		return accountName;
	}

	public String getAccountPassword() {
		return accountPassword;
	}

	public void setAccountPassword(String accountPassword) {
		this.accountPassword = accountPassword;
	}

	public String getAccountEmail() {
		return accountEmail;
	}

	public void setAccountEmail(String accountEmail) {
		this.accountEmail = accountEmail;
	}

	public void setAccountManager(AccountManager accountManager) {
		this.accountManager = accountManager;
	}

}
